package net.system.sys.action;

import java.util.HashMap;
import java.util.List;

import net.core.base.struts.BaseAction;
import net.core.common.HttpUtil;
import net.system.base.bean.SSysdict;
import net.system.sys.service.IDictService;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

@Scope("request")
@Namespace("/system/dict")
@InterceptorRefs(@InterceptorRef("basicStack"))
@ParentPackage("struts-default")
@Results({ @Result(name = "error", location = "/login.jsp") })
public class DictAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	@Autowired
	IDictService service;
	private List<SSysdict> list;
	private String formFlag = "0";

	@Action(value = "dict", results = { @Result(name = "success", location = "/WEB-INF/pages/system/dict/Dict.jsp") })
	public String dict() {
		// 字典管理界面包含查询及列表内容
		list = service.selectDict();
		return SUCCESS;
	}

	@Action(value = "searchDict", results = { @Result(name = "success", location = "/WEB-INF/pages/system/dict/Dict.jsp") })
	public String searchDict() {
		// 字典管理界面包含查询及列表内容
		return SUCCESS;
	}
	
	@Action(value = "addDict", results = { @Result(name = "success", location = "/WEB-INF/pages/system/dict/DictAdd.jsp") })
	public String addDict() {
		// 添加页面
		return SUCCESS;
	}

	@Action(value = "saveDict", results = { @Result(name = "success", location = "/WEB-INF/pages/system/dict/DictAdd.jsp") })
	public String saveDict() {
		// 保存字典内容
		HashMap reqMap = new HashMap();
		reqMap = HttpUtil.buildParameterMap(getRequest());
		System.out.println(reqMap.toString());
		service.saveDict(reqMap);
		//list = service.selectDict();
		formFlag="1";
		return SUCCESS;
	}

	@Action(value = "updateDict", results = { @Result(name = "success", location = "/WEB-INF/pages/system/dict/Dict.jsp") })
	public String updateDict() {
		// 更新字典内容
		return SUCCESS;
	}

	@Action(value = "deleteDict", results = { @Result(name = "success", location = "/WEB-INF/pages/system/dict/Dict.jsp") })
	public String deleteDict() {
		// 删除字典内容
		return SUCCESS;
	}

	public List<SSysdict> getList() {
		return list;
	}

	public void setList(List<SSysdict> list) {
		this.list = list;
	}

	public String getFormFlag() {
		return formFlag;
	}

	public void setFormFlag(String formFlag) {
		this.formFlag = formFlag;
	}
}
